package com.shop2cn.iapi.agentproducts.testcase;

import java.util.Arrays;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.agentproducts.parameter.AddAgentProductBean;
import com.shop2cn.iapi.agentproducts.parameter.GetCatalogBySkuBean;
import com.shop2cn.iapi.agentproducts.parameter.SubCatalogDto;
import com.shop2cn.iapi.agentproducts.service.GetCatalogBySkuCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.AddAgentProductCallService;
import com.ymttest.utils.AgentUsers;
/**
*通过skuId获取规格信息Test
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetCatalogBySku{
	private static GetCatalogBySkuBean getcatalogbyskuBean;
	private static GetCatalogBySkuCall getcatalogbyskuCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("通过skuId获取规格信息Test");
	}

	@Before
	public void caseUp() {
		getcatalogbyskuBean=new GetCatalogBySkuBean();
		getcatalogbyskuCall=new GetCatalogBySkuCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getcatalogbyskuCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	// 渠道商
		private static int sellerId = AgentUsers.rootUserId;
		private static String sellerName = "NickautoTest";
		
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetCatalogBySku_001() {
		Logger.start(true,"正确数据，成功");
		try {
			
			AddAgentProductBean Product1 = AddAgentProductCallService.initAddAgentProduct(sellerId,
					sellerName, true);
			Product1.getCatalogList().remove(0);
			String productId1 = AddAgentProductCallService.AddAgentProduct(Product1);
			
			
			AddAgentProductBean Product2 = AddAgentProductCallService.initAddAgentProduct(sellerId,
					sellerName, true);
			Product2.getCatalogList().remove(0);
			String productId2 = AddAgentProductCallService.AddAgentProduct(Product2);
			
			AddAgentProductBean addAgentProductBean=AddAgentProductCallService.initAddAgentProduct(sellerId,sellerName, true);
			
			addAgentProductBean.getCatalogList().remove(1);
			SubCatalogDto subCatalogDto = new SubCatalogDto();
			subCatalogDto.setSkuId(Product1.getCatalogList().get(0).getSku());
			subCatalogDto.setBarcode(Product1.getCatalogList().get(0).getBarcode());
			subCatalogDto.setSalePrice(Product1.getCatalogList().get(0).getDirectPrice());
			subCatalogDto.setNum(10);
			
			
			SubCatalogDto subCatalogDto1 = new SubCatalogDto();
			subCatalogDto1.setSkuId(Product2.getCatalogList().get(0).getSku());
			subCatalogDto1.setBarcode(Product2.getCatalogList().get(0).getBarcode());
			subCatalogDto1.setSalePrice(Product2.getCatalogList().get(0).getDirectPrice());
			subCatalogDto1.setNum(10);
			
			addAgentProductBean.setSubCatalogs(Arrays.asList(subCatalogDto,subCatalogDto1));
			
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			Thread.sleep(2000);
			
			getcatalogbyskuBean.setSkuId(addAgentProductBean.getCatalogList().get(0).getSku());
			getcatalogbyskuBean.setUserId(sellerId);
			getcatalogbyskuCall.setData(getcatalogbyskuBean);
			getcatalogbyskuCall.callService();			
			Logger.verifyEquals("200", getcatalogbyskuCall.getString("code"), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}